<template>
	<view>
		<swiper :style="{'height':swiperHeight+'px'}" :autoplay="true">
			<swiper-item v-for="item in ad_list">
				<view class="ad" :style="{'background-image': 'url(' + item.pic + ')'}">
					<u-count-down style="margin-top: 40rpx;margin-right: 40rpx;" :timestamp="6" :show-hours="false" :show-minutes="false" @end="to_index"></u-count-down>
					<u-button style="position:absolute;right:15rpx;bottom:15rpx;"
					 type="primary" size="mini" shape="circle" :plain="true" :hair-line="false" @click="to_index">
						立即跳过
					</u-button>
				</view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				ad_list:[],
				swiperHeight:0
			}
		},
		onLoad() {
			var that = this;
			uni.getSystemInfo({
				success(res) {
					that.swiperHeight = res.screenHeight;
				}
			})
			this.init();
		},
		methods: {
			to_index() {
				uni.switchTab({
					url:'index'
				})
			},
			init:function(){
				//获取广告
				uni.request({
					url: `${this.$serverUrl}/start_ad`,
					header: {
						"Content-Type": "application/json"
					},
					method: "GET",
					success: (e) => {
						if (e.data.status == 200) {
							this.ad_list = e.data.data;
						} else {
							this.$toast_fail(e.data);
						}
					},
					fail: (e) => {
						this.$toast_fail({msg:"请求失败"});
					}
				});
			}
		}
	}
</script>

<style>
	.ad {
		width:100%;
		height:100%;
		background-size: 100% 100%;
		text-align: right;
	}
</style>
